#ifndef NODE_H
#define NODE_H

#include <QApplication>
#include <QColor>
#include <QGraphicsItem>
#include <QSet>
#include <QMouseEvent>

QT_BEGIN_NAMESPACE
class Link;
QT_END_NAMESPACE

class Node : public QGraphicsItem
{
    Q_DECLARE_TR_FUNCTIONS(Node)

public:
    enum E_NodeSearchStatus
    {
        NotFind = 0,
        FindSide,
        AllFind,
    };

    Node(int iID);
    ~Node();

    int id() const
    {
        return m_iID;
    }

    void setText(const QString &text);
    QString text() const;
    void setTextColor(const QColor &color);
    QColor textColor() const;
    void setOutlineColor(const QColor &color);
    QColor outlineColor() const;
    void setBackgroundColor(const QColor &color);
    QColor backgroundColor() const;

    void setSearchStatus(E_NodeSearchStatus status);
    E_NodeSearchStatus getSearchStatus() const;

    void setSearchDepth(int iDepth);
    int getSearchDepth() const;

    void setParentItem(Node *pParentNode);
    Node *getParentItem() const;

    void addLink(Link *link);
    void removeLink(Link *link);

    void addNeighbour(Node *pNode);
    void removeNeighbour(Node *pNode);

    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter,
               const QStyleOptionGraphicsItem *option, QWidget *widget);

    QSet<Node *> getNeighbourSet() const;

    int type();

protected:
    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
    QVariant itemChange(GraphicsItemChange change,
                        const QVariant &value);

private:
    QRectF outlineRect() const;
    int roundness(double size) const;

    QSet<Link *> m_linkSet;
    QSet<Node *> m_neighbourNodeSet;
    QString myText;
    QColor myTextColor;
    QColor myBackgroundColor;
    QColor myOutlineColor;

    E_NodeSearchStatus m_nodeSearchStatus;
    int m_iSearchDepth;
    Node *m_pParentNode;
    int m_iID;
};



#endif
